﻿using System.Collections.Generic;
using System.IO;


namespace JsonDaHelper
{
    public class FileUtil
    {
        public static IEnumerable<string> FindDisk()
        {
            var ds = DriveInfo.GetDrives();
            foreach (var d in ds)
            {
                yield return d.Name;
            }
        }


        /// <summary>
        /// 后缀名，文件夹
        /// </summary>
        /// <param name="ext"></param>
        /// <param name="folder"></param>
        public static string SearchFile(string fileName, string disk)
        {
            if (!Directory.Exists(disk))
                return "";
            var compiler = new System.Diagnostics.Process();
            compiler.StartInfo.FileName = "cmd.exe";
            compiler.StartInfo.CreateNoWindow = true;
            compiler.StartInfo.UseShellExecute = false;
            compiler.StartInfo.RedirectStandardInput = true;
            compiler.StartInfo.RedirectStandardOutput = true;
            var strCmd = $"dir {disk} /s /b|find \"{fileName}\"";

            compiler.Start();
            compiler.StandardInput.WriteLine(strCmd);
            compiler.StandardInput.WriteLine("exit");
            var strRst = compiler.StandardOutput.ReadToEnd();
            compiler.Close();
            return strRst;
        }
    }
}